package com.starinside.wp.controller;

import com.starinside.wp.domain.WxUser;
import com.starinside.wp.foundation.model.StatusResponse;
import com.starinside.wp.utils.HttpClient;
import com.starinside.wp.utils.JsonUtil;
import com.starinside.wp.utils.RemoteCallUtil;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;



@RestController
@RequestMapping("/aboutPallet")
@Api(tags = "预约试托")
public class CrmPalletApiController {


    @Value("${server.crm.url}")
    private String crmServerURL;



    /**
     * 获取预约试托列表
     */
    @PostMapping("/getList")
    public StatusResponse getList(@RequestBody Map aboutPallet) throws IOException {
        String json = HttpClient.doPost(crmServerURL + "/api/aboutPallet/getList",aboutPallet);
        Map map = JsonUtil.readToMap(json);
        return StatusResponse.success(map.get("data"));
    }

  /*  *//**
     * 获取预约试托
     *//*
    @GetMapping("/get")
    public StatusResponse get(@RequestHeader String ticket,String id) {
        Map p = new HashMap();
        p.put("id",id);
        HashMap result = RemoteCallUtil.call(crmServerURL + "/api/aboutPallet/get", p, ticket, HashMap.class, "查询失败");
        return StatusResponse.success(result);
    }*/

    /**
     * 添加预约试托
     */
    @PostMapping("/wpAdd")
    public Map wpAdd(@RequestHeader String ticket,@RequestBody Map<String, Object> aboutPallet) throws IOException {
        String json = HttpClient.doPost(crmServerURL + "/api/aboutPallet/wpAdd",aboutPallet);
        Map map = JsonUtil.readToMap(json);
        return map;
    }


    /**
     * 修改预约试托
     */
    @PostMapping("/update")
    public StatusResponse update(@RequestHeader String ticket,@RequestBody Map aboutPallet) {
        HashMap result = RemoteCallUtil.call(crmServerURL + "/api/aboutPallet/update", aboutPallet, ticket, HashMap.class, "修改失败");
        return StatusResponse.success(result);
    }

    /**
     * 删除预约试托
     */
    @PostMapping("/delete")
    public void delete(@RequestHeader String ticket,String id) {
        Map p = new HashMap();
        p.put("id",id);
        HashMap result = RemoteCallUtil.call(crmServerURL + "/api/aboutPallet/delete", p, ticket, HashMap.class, "删除失败");
    }

}
